package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.BrandCategoryAddNewDTO;
import cn.tedu.csmall.product.service.IBrandCategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@Api(tags = "04.品牌与类别关联管理模块")
@RequestMapping("/brand-categories")
@RestController
public class BrandCategoryController {
    @Autowired
    private IBrandCategoryService brandCategoryService;
    @PostMapping("/bind")
    @ApiOperation("绑定品牌与类别关联")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> bind(@Valid BrandCategoryAddNewDTO brandCategoryAddNewDTO){
        log.debug("即将处理添加品牌与类别关联的请求,参数:{}",brandCategoryAddNewDTO);
        brandCategoryService.bind(brandCategoryAddNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("解绑品牌与类别关联")
    @ApiOperationSupport(order = 110)
    @ApiImplicitParam(name = "id",value = "品牌与类别关联id",required = true,dataType = "long")
    @PostMapping("/{id:[0-9]+}/unbind")
    public JsonResult<Void> unbind(@PathVariable Long id){
        log.debug("即将处理解绑品牌与类别关联的请求,参数:id={}",id);
        brandCategoryService.unbind(id);
        return JsonResult.ok();
    }
}
